package com.yan.demo.demo1;

import com.yan.demo.demo1.Account;

/**
 * @author taoge
 * @Date 2024/8/8 9:21
 * @Description
 */
class Task1 implements Runnable{

    private Account account;

    public Task1(Account account) {
        this.account = account;
    }

    @Override
    public synchronized void run() {
            if(account.getMoney() > 3000){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                account.setMoney(account.getMoney() - 3000);
                System.out.println(Thread.currentThread().getName() + "取钱成功" + "剩" + account.getMoney());
            }else{
                System.out.println("余额不足");
            }
    }
}
